using System;
namespace CtxReader {
	[Serializable]
	public class ByteBuffer {
		private byte[] _buffer;
		private int _chunk;
		private int _length;
		public ByteBuffer() {
			this._length=0;
			this._chunk=0x40;
			this._buffer=new byte[this._chunk];
		}
		public ByteBuffer(int chunk) {
			this._length=0;
			this._chunk=0x40;
			this._chunk=chunk;
			this._buffer=new byte[this._chunk];
		}
		public int Append(byte[] bytes) {
			return this.Append(bytes,bytes.Length);
		}
		public int Append(byte byteValue) {
			byte[] bytes=new byte[] { byteValue };
			return this.Append(bytes,1);
		}
		public int Append(byte[] bytes,int count) {
			int num=this._length+count;
			if(num>this._buffer.Length)
			{
				int num2=this._buffer.Length+((((num-this._buffer.Length)/this._chunk)+1)*this._chunk);
				byte[] destinationArray=new byte[this._buffer.Length];
				Array.Copy(this._buffer,0,destinationArray,0,this._buffer.Length);
				this._buffer=new byte[num2];
				Array.Copy(destinationArray,0,this._buffer,0,destinationArray.Length);
			}
			Array.Copy(bytes,0,this._buffer,this._length,count);
			this._length+=count;
			return this._length;
		}
		public int Append(byte[] bytes,int count,int start) {
			int num=this._length+count;
			if(num>this._buffer.Length)
			{
				int num2=this._buffer.Length+((((num-this._buffer.Length)/this._chunk)+1)*this._chunk);
				byte[] destinationArray=new byte[this._buffer.Length];
				Array.Copy(this._buffer,0,destinationArray,0,this._buffer.Length);
				this._buffer=new byte[num2];
				Array.Copy(destinationArray,0,this._buffer,0,destinationArray.Length);
			}
			Array.Copy(bytes,start,this._buffer,this._length,count);
			this._length+=count;
			return this._length;
		}
		public void Clear() {
			this._length=0;
		}
		public void Copy(ByteBuffer copy) {
			this._length=copy._length;
			this._chunk=copy._chunk;
			this._buffer=new byte[copy._buffer.Length];
			Array.Copy(copy._buffer,0,this._buffer,0,this._buffer.Length);
		}
		public byte GetAt(int index) {
			return this._buffer[index];
		}
		public byte[] GetBytes() {
			byte[] destinationArray=new byte[this._length];
			Array.Copy(this._buffer,0,destinationArray,0,this._length);
			return destinationArray;
		}
		public byte[] Remove(int count) {
			byte[] destinationArray=new byte[count];
			Array.Copy(this._buffer,0,destinationArray,0,count);
			Array.Copy(this._buffer,count,this._buffer,0,this._length-count);
			this._length-=count;
			return destinationArray;
		}
		public int Set(byte[] bytes,int count) {
			int num=count;
			if(num>this._buffer.Length)
			{
				int num2=this._buffer.Length+((((num-this._buffer.Length)/this._chunk)+1)*this._chunk);
				byte[] destinationArray=new byte[this._buffer.Length];
				Array.Copy(this._buffer,0,destinationArray,0,this._buffer.Length);
				this._buffer=new byte[num2];
				Array.Copy(destinationArray,0,this._buffer,0,destinationArray.Length);
			}
			Array.Copy(bytes,0,this._buffer,0,count);
			this._length=count;
			return this._length;
		}
		public int Length {
			get {
				return this._length;
			}
		}
	}
}
